<template>
  <div class="fg1 hf y jc oh">
    <h3 class="p10px" v-html="'物料信息'" />
    <div class="x p10px wf">
      <el-button
        v-if="pid"
        type="primary"
        v-html="'新增物料'"
        @click="itemC=$cp(defItem);show = !show"
      />
    </div>
    <div class="fg1 wf y jc oh" style="padding:0px 0px 0px 10px">
      <el-table
        :data="tabData"
        border
        stripe
        highlight-current-row
        style="width: 100%"
        max-height="100%"
        @row-click="addDepository"
        height="100"
        class
      >
        <el-table-column fixed type="index" label="行号" width="50" />
        <el-table-column prop="id" label="id" width="80" />
        <el-table-column prop="uid" label="物料编号" width="100" />
        <el-table-column prop="name" label="名称" width="180" />
        <el-table-column prop="model" label="型号" width="180" />
        <el-table-column label="操作" width="80">
          <template slot-scope="scope">
            <el-button
              type="primary"
              @click="itemC=scope.row; show=!show"
              v-html="'修改'"
              size="mini"
            />
          </template>
        </el-table-column>
        <el-table-column prop="other.remarks" label="备注" />
      </el-table>
      <fy :value="data" @change="tabData=$event" />
    </div>
    <createItem :fshow="show" :form="itemC" @change="change" />
  </div>
</template>

<script>
import createItem from "../components/create/itemA.vue";
import fy from "../components/fy";
export default {
  components: { createItem, fy },
  props: ["data", "pid"],
  watch: {
    pid(a) {
      this.defItem.pid = a;
    }
  },
  data() {
    return {
      show: false,
      itemC: {},
      defItem: {
        id: 0,
        cid: 0,
        pid: 0,
        uid: 0,
        name: "",
        units: [],
        sum: 0,
        other: { remarks: "" }
      },
      tabData: []
    };
  },
  created() {
    this.itemC = this.$cp(this.defItem);
  },
  methods: {
    addDepository(a) {
      this.$emit("change", { add: { id: a.id, sum: 0, name: a.name } });
    },
    change(a, b, c) {
      switch (a) {
        case 201:
          if (c) {
            this.data.push(b);
            this.$gd.items.push(b);
          }
          break;

        default:
          break;
      }
    }
  }
};
</script>

<style lang="less" scoped>
.gx {
  overflow-x: auto;
}
</style>
